libraries/EaselJS_docs/classes/Utility Methods.html (view raw)
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
6 <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
7 <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
8 <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
9 <script src="../assets/js/yui-source.js"></script>
10 <title>EaselJS v1.0.0 API Documentation : Utility Methods</title>
11</head>
12<body class="yui3-skin-sam">
13
14<div id="doc">
15 <div id="hd" class="yui3-g header">
16 <div class="yui3-u-3-4">
17
18 <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
19
20 </div>
21 <div class="version">
22 <em>API Documentation for: 1.0.0</em>
23 </div>
24 </div>
25 <div id="bd" class="yui3-g">
26
27 <div class="yui3-u-1-4">
28 <div id="docs-sidebar" class="sidebar apidocs">
29 <div id="api-list">
30 <h2 class="off-left">APIs</h2>
31 <div id="api-tabview" class="tabview">
32 <ul class="tabs">
33 <li><a href="#api-classes">Classes</a></li>
34 </ul>
35
36 <div id="api-tabview-filter">
37 <input type="search" id="api-filter" placeholder="Type to filter APIs">
38 </div>
39
40 <div id="api-tabview-panel">
41 <ul id="api-classes" class="apis classes">
42
43 <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
44
45 <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
46
47 <li><a href="../classes/Bitmap.html">Bitmap</a></li>
48
49 <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
50
51 <li><a href="../classes/BitmapText.html">BitmapText</a></li>
52
53 <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
54
55 <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
56
57 <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
58
59 <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
60
61 <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
62
63 <li><a href="../classes/Container.html">Container</a></li>
64
65 <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
66
67 <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
68
69 <li><a href="../classes/DOMElement.html">DOMElement</a></li>
70
71 <li><a href="../classes/EaselJS.html">EaselJS</a></li>
72
73 <li><a href="../classes/Event.html">Event</a></li>
74
75 <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
76
77 <li><a href="../classes/Filter.html">Filter</a></li>
78
79 <li><a href="../classes/Graphics.html">Graphics</a></li>
80
81 <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
82
83 <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
84
85 <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
86
87 <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
88
89 <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
90
91 <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
92
93 <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
94
95 <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
96
97 <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
98
99 <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100
101 <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102
103 <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104
105 <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106
107 <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108
109 <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110
111 <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112
113 <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114
115 <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116
117 <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118
119 <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120
121 <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122
123 <li><a href="../classes/Point.html">Point</a></li>
124
125 <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126
127 <li><a href="../classes/Shadow.html">Shadow</a></li>
128
129 <li><a href="../classes/Shape.html">Shape</a></li>
130
131 <li><a href="../classes/Sprite.html">Sprite</a></li>
132
133 <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134
135 <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136
137 <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138
139 <li><a href="../classes/Stage.html">Stage</a></li>
140
141 <li><a href="../classes/StageGL.html">StageGL</a></li>
142
143 <li><a href="../classes/Text.html">Text</a></li>
144
145 <li><a href="../classes/Ticker.html">Ticker</a></li>
146
147 <li><a href="../classes/Touch.html">Touch</a></li>
148
149 <li><a href="../classes/UID.html">UID</a></li>
150
151 <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152
153 <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154
155 <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156
157 </ul>
158
159 <ul id="api-modules" class="apis modules">
160
161 <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162
163 <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164
165 </ul>
166 </div>
167 </div>
168</div>
169
170 </div>
171 </div>
172 <div class="yui3-u-3-4">
173 <div id="api-options">
174 Show:
175 <label for="api-show-inherited">
176 <input type="checkbox" id="api-show-inherited" checked>
177 Inherited
178 </label>
179
180 <label for="api-show-protected">
181 <input type="checkbox" id="api-show-protected">
182 Protected
183 </label>
184
185 <label for="api-show-private">
186 <input type="checkbox" id="api-show-private">
187 Private
188 </label>
189 <label for="api-show-deprecated">
190 <input type="checkbox" id="api-show-deprecated">
191 Deprecated
192 </label>
193
194 </div>
195 <div class="apidocs">
196 <div id="docs-main">
197 <div class="content">
198 <h1>Utility Methods Class</h1>
199<div class="box meta">
200
201
202
203
204
205 <div class="foundat">
206 Defined in: <a href="../files/createjs_utils_promote.js.html#l36"><code>Utility Methods:36</code></a>
207 </div>
208
209
210
211
212 Module: <a href="../modules/CreateJS.html">CreateJS</a>
213
214
215
216
217</div>
218
219
220
221<div class="box intro">
222
223</div>
224
225
226
227<div id="classdocs" class="tabview">
228 <ul class="api-class-tabs">
229 <li class="api-class-tab index"><a href="#index">Index</a></li>
230
231
232 <li class="api-class-tab methods"><a href="#methods">Methods</a></li>
233
234
235
236
237 </ul>
238
239 <div>
240 <div id="index" class="api-class-tabpanel index">
241 <h2 class="off-left">Item Index</h2>
242
243
244 <div class="index-section methods">
245 <h3>Methods</h3>
246
247 <ul class="index-list methods">
248
249 <li class="index-item method">
250 <a href="#method_deprecate">deprecate</a>
251
252
253
254 </li>
255
256 <li class="index-item method">
257 <a href="#method_extend">extend</a>
258
259
260
261 </li>
262
263 <li class="index-item method">
264 <a href="#method_indexOf">indexOf</a>
265
266
267
268 </li>
269
270 <li class="index-item method">
271 <a href="#method_promote">promote</a>
272
273
274
275 </li>
276
277 </ul>
278 </div>
279
280
281
282
283
284
285
286 </div>
287
288
289 <div id="methods" class="api-class-tabpanel">
290 <h2 class="off-left">Methods</h2>
291
292
293 <div id="method_deprecate" class="method item">
294 <h3 class="name"><code>deprecate</code></h3>
295
296
297 <div class="args">
298 <span class="paren">(</span><ul class="args-list inline commas">
299
300 <li class="arg">
301
302 <code class="optional">[fallbackMethod=null]</code>
303
304 </li>
305
306 <li class="arg">
307
308 <code class="optional">[name=null]</code>
309
310 </li>
311
312 </ul><span class="paren">)</span>
313 </div>
314
315
316
317 <span class="returns-inline">
318 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
319 </span>
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334 <div class="meta">
335
336
337
338 <p>
339
340 Defined in
341
342
343
344
345 <a href="../files/createjs_utils_deprecate.js.html#l40"><code>deprecate:40</code></a>
346
347 </p>
348
349
350
351
352
353 </div>
354
355 <div class="description">
356 <p>Wraps deprecated methods so they still be used, but throw warnings to developers.</p>
357<pre class="code prettyprint"><code>obj.deprecatedMethod = createjs.deprecate("Old Method Name", obj._fallbackMethod);</code></pre>
358<p>The recommended approach for deprecated properties is:</p>
359<pre class="code prettyprint"><code>try {
360 Obj ect.defineProperties(object, {
361 readyOnlyProp: { get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }) },
362 readWriteProp: {
363 get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }),
364 set: createjs.deprecate("readOnlyProp", function(val) { this.alternateProp = val; })
365 });
366} catch (e) {}</code></pre>
367
368 </div>
369
370
371 <div class="params">
372 <h4>Parameters:</h4>
373
374 <ul class="params-list">
375
376 <li class="param">
377
378 <code class="param-name optional">[fallbackMethod=null]</code>
379 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
380 <span class="flag optional" title="This parameter is optional.">optional</span>
381
382
383
384
385 <div class="param-description">
386 <p>A method to call when the deprecated method is used. See the example for how</p>
387
388 </div>
389
390
391 </li>
392
393 <li class="param">
394
395 <code class="param-name optional">[name=null]</code>
396 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
397 <span class="flag optional" title="This parameter is optional.">optional</span>
398
399
400
401
402 <div class="param-description">
403 <p>The name of the method or property to display in the console warning.
404to deprecate properties.</p>
405
406 </div>
407
408
409 </li>
410
411 </ul>
412 </div>
413
414
415
416 <div class="returns">
417 <h4>Returns:</h4>
418
419 <div class="returns-description">
420
421
422 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>:
423
424 <p>If a fallbackMethod is supplied, returns a closure that will call the fallback method after
425logging the warning in the console.</p>
426
427
428 </div>
429 </div>
430
431
432
433</div>
434
435
436 <div id="method_extend" class="method item">
437 <h3 class="name"><code>extend</code></h3>
438
439
440 <div class="args">
441 <span class="paren">(</span><ul class="args-list inline commas">
442
443 <li class="arg">
444
445 <code>subclass</code>
446
447 </li>
448
449 <li class="arg">
450
451 <code>superclass</code>
452
453 </li>
454
455 </ul><span class="paren">)</span>
456 </div>
457
458
459
460 <span class="returns-inline">
461 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
462 </span>
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477 <div class="meta">
478
479
480
481 <p>
482
483 Defined in
484
485
486
487
488 <a href="../files/createjs_utils_extend.js.html#l40"><code>extend:40</code></a>
489
490 </p>
491
492
493
494
495
496 </div>
497
498 <div class="description">
499 <p>Sets up the prototype chain and constructor property for a new class.</p>
500<p>This should be called right after creating the class constructor.</p>
501<pre class="code prettyprint"><code>function MySubClass() {}
502createjs.extend(MySubClass, MySuperClass);
503MySubClass.prototype.doSomething = function() { }
504
505var foo = new MySubClass();
506console.log(foo instanceof MySuperClass); // true
507console.log(foo.prototype.constructor === MySubClass); // true</code></pre>
508
509 </div>
510
511
512 <div class="params">
513 <h4>Parameters:</h4>
514
515 <ul class="params-list">
516
517 <li class="param">
518
519 <code class="param-name">subclass</code>
520 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
521
522
523
524
525 <div class="param-description">
526 <p>The subclass.</p>
527
528 </div>
529
530
531 </li>
532
533 <li class="param">
534
535 <code class="param-name">superclass</code>
536 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
537
538
539
540
541 <div class="param-description">
542 <p>The superclass to extend.</p>
543
544 </div>
545
546
547 </li>
548
549 </ul>
550 </div>
551
552
553
554 <div class="returns">
555 <h4>Returns:</h4>
556
557 <div class="returns-description">
558
559
560 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>:
561
562 <p>Returns the subclass's new prototype.</p>
563
564
565 </div>
566 </div>
567
568
569
570</div>
571
572
573 <div id="method_indexOf" class="method item">
574 <h3 class="name"><code>indexOf</code></h3>
575
576
577 <div class="args">
578 <span class="paren">(</span><ul class="args-list inline commas">
579
580 <li class="arg">
581
582 <code>array</code>
583
584 </li>
585
586 <li class="arg">
587
588 <code>searchElement</code>
589
590 </li>
591
592 </ul><span class="paren">)</span>
593 </div>
594
595
596
597 <span class="returns-inline">
598 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number" class="crosslink external" target="_blank">Number</a></span>
599 </span>
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614 <div class="meta">
615
616
617
618 <p>
619
620 Defined in
621
622
623
624
625 <a href="../files/createjs_utils_indexOf.js.html#l40"><code>indexOf:40</code></a>
626
627 </p>
628
629
630
631
632
633 </div>
634
635 <div class="description">
636 <p>Finds the first occurrence of a specified value searchElement in the passed in array, and returns the index of
637that value. Returns -1 if value is not found.</p>
638<pre class="code prettyprint"><code> var i = createjs.indexOf(myArray, myElementToFind);</code></pre>
639
640 </div>
641
642
643 <div class="params">
644 <h4>Parameters:</h4>
645
646 <ul class="params-list">
647
648 <li class="param">
649
650 <code class="param-name">array</code>
651 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array" class="crosslink external" target="_blank">Array</a></span>
652
653
654
655
656 <div class="param-description">
657 <p>Array to search for searchElement</p>
658
659 </div>
660
661
662 </li>
663
664 <li class="param">
665
666 <code class="param-name">searchElement</code>
667 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
668
669
670
671
672 <div class="param-description">
673 <p>Element to find in array.</p>
674
675 </div>
676
677
678 </li>
679
680 </ul>
681 </div>
682
683
684
685 <div class="returns">
686 <h4>Returns:</h4>
687
688 <div class="returns-description">
689
690
691 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number" class="crosslink external" target="_blank">Number</a></span>:
692
693 <p>The first index of searchElement in array.</p>
694
695
696 </div>
697 </div>
698
699
700
701</div>
702
703
704 <div id="method_promote" class="method item">
705 <h3 class="name"><code>promote</code></h3>
706
707
708 <div class="args">
709 <span class="paren">(</span><ul class="args-list inline commas">
710
711 <li class="arg">
712
713 <code>subclass</code>
714
715 </li>
716
717 <li class="arg">
718
719 <code>prefix</code>
720
721 </li>
722
723 </ul><span class="paren">)</span>
724 </div>
725
726
727
728 <span class="returns-inline">
729 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
730 </span>
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745 <div class="meta">
746
747
748
749 <p>
750
751 Defined in
752
753
754
755
756 <a href="../files/createjs_utils_promote.js.html#l40"><code>promote:40</code></a>
757
758 </p>
759
760
761
762
763
764 </div>
765
766 <div class="description">
767 <p>Promotes any methods on the super class that were overridden, by creating an alias in the format <code>prefix_methodName</code>.
768It is recommended to use the super class's name as the prefix.
769An alias to the super class's constructor is always added in the format <code>prefix_constructor</code>.
770This allows the subclass to call super class methods without using <code>function.call</code>, providing better performance.</p>
771<p>For example, if <code>MySubClass</code> extends <code>MySuperClass</code>, and both define a <code>draw</code> method, then calling <code>promote(MySubClass, "MySuperClass")</code>
772would add a <code>MySuperClass_constructor</code> method to MySubClass and promote the <code>draw</code> method on <code>MySuperClass</code> to the
773prototype of <code>MySubClass</code> as <code>MySuperClass_draw</code>.</p>
774<p>This should be called after the class's prototype is fully defined.</p>
775<pre class="code prettyprint"><code>function ClassA(name) {
776 this.name = name;
777}
778ClassA.prototype.greet = function() {
779 return "Hello "+this.name;
780}
781
782function ClassB(name, punctuation) {
783 this.ClassA_constructor(name);
784 this.punctuation = punctuation;
785}
786createjs.extend(ClassB, ClassA);
787ClassB.prototype.greet = function() {
788 return this.ClassA_greet()+this.punctuation;
789}
790createjs.promote(ClassB, "ClassA");
791
792var foo = new ClassB("World", "!?!");
793console.log(foo.greet()); // Hello World!?!</code></pre>
794
795 </div>
796
797
798 <div class="params">
799 <h4>Parameters:</h4>
800
801 <ul class="params-list">
802
803 <li class="param">
804
805 <code class="param-name">subclass</code>
806 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
807
808
809
810
811 <div class="param-description">
812 <p>The class to promote super class methods on.</p>
813
814 </div>
815
816
817 </li>
818
819 <li class="param">
820
821 <code class="param-name">prefix</code>
822 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
823
824
825
826
827 <div class="param-description">
828 <p>The prefix to add to the promoted method names. Usually the name of the superclass.</p>
829
830 </div>
831
832
833 </li>
834
835 </ul>
836 </div>
837
838
839
840 <div class="returns">
841 <h4>Returns:</h4>
842
843 <div class="returns-description">
844
845
846 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>:
847
848 <p>Returns the subclass.</p>
849
850
851 </div>
852 </div>
853
854
855
856</div>
857
858
859 </div>
860
861
862
863
864
865
866
867 </div>
868</div>
869
870 </div>
871 </div>
872 </div>
873 </div>
874 </div>
875</div>
876<script src="../assets/vendor/prettify/prettify-min.js"></script>
877<script>prettyPrint();</script>
878<script src="../assets/js/yui-prettify.js"></script>
879<script src="../assets/../api.js"></script>
880<script src="../assets/js/api-filter.js"></script>
881<script src="../assets/js/api-list.js"></script>
882<script src="../assets/js/api-search.js"></script>
883<script src="../assets/js/apidocs.js"></script>
884</body>
885</html>